/**
 * Created by dukes on 2015/10/22.
 */
//module game{
    class AdoptItemRender extends eui.ItemRenderer{
        constructor(){
            super();
            this.skinName = "pet.AdoptMissionItemSkin";
            this.addEventListener(egret.Event.ADDED_TO_STAGE,this.addedToStage, this );
            this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.removedFromStage, this);
        }
        private addedToStage(evt:egret.Event){
            this.img_get.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onGet,this);
        }

        private removedFromStage(evt:egret.Event){
            this.img_get.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onGet,this);
        }
        public img_bg:eui.Image;
        public lab_desc:eui.Label;
        public img_money:eui.Image;
        public group_money:eui.BitmapLabel;
        public img_complete:eui.Image;
        public img_get:eui.Image;
        public lab_progress:eui.Label;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name == "img_bg" ){
                this.img_bg = instance;
            }else if( name == "lab_desc" ){
                this.lab_desc = instance;
            }else if( name == "img_money" ){
                this.img_money = instance;
            }else if( name == "group_money" ){
                this.group_money = instance;
                this.group_money.textAlign = "center";
            }else if( name == "img_get" ){
                this.img_get = instance;
            }else if( name == "img_complete" ){
                this.img_complete = instance;
            }else if( name == "lab_progress" ){
                this.lab_progress = instance;
            }
        }
        public onGet(evt:egret.TouchEvent){
            SoundMgr.getInstance().playEffect(SoundMgr.BTN);
            window["__missionAward"](this.data);
        }
        public dataChanged(){
            super.dataChanged();
            var mission:any = Model.unlockModels[this.data];
            var hairPrize:number = mission.dogHair || mission.catHair;
            this.lab_desc.text = mission.name;
            if(hairPrize != 0){
                this.img_money.source = mission.dogHair == 0 ? "img_money_cat" : "img_money_dog";
                // this.img_money.commitProperties();
                this.group_money.text = GetNumString(hairPrize,false,true);
                return;
            }
            if(mission.diamond!=0){
                this.img_money.source = "img_diamond";
                this.group_money.text = GetNumString(mission.diamond,false,true);
            }
            this.img_get.visible = mission.status  == 1;//已领取
            this.img_complete.visible = mission.status == 2 || Model.finishedMissions.indexOf(this.data) != -1;//已完成
            if( !this.img_get.visible && !this.img_complete.visible && Model.finishedMissions.indexOf(this.data) == -1) {
                this.lab_progress.visible = true;
                this.lab_progress.text =  mission.currStep+"/"+mission.steps;
            }else{
                this.lab_progress.visible = false;
            }
        }
    }
//}